//
//  SDDetectionReportHeaderView.m
//  skinDetection
//
//  Created by  liangzhun on 2018/11/5.
//  Copyright © 2018年  liangzhun. All rights reserved.
//

#import "SDDetectionReportHeaderView.h"

@implementation SDDetectionReportHeaderView


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    self.bgView.layer.cornerRadius = 9.0f;
    self.bgView.layer.masksToBounds = YES;


    
}

- (void)addLayer
{
   
    if (self.bgLayer) {
        return;
    }
    
    self.bgLayer = [[CAGradientLayer alloc] init];
    self.bgLayer.colors = @[(__bridge id)RGBA(255, 120, 155, 1).CGColor,(__bridge id)RGBA(250, 207, 92, 1).CGColor];
    self.bgLayer.locations = @[@0.5,@1];
    self.bgLayer.startPoint = CGPointMake(0, 0);
    self.bgLayer.endPoint = CGPointMake(1, 0.7);
    self.bgLayer.frame = CGRectMake(0, 0, SDMainScreenWidth, self.topHeight.constant);
    [self.topView.layer insertSublayer:self.bgLayer above:0];
    
    CALayer *layer = [[CALayer alloc] init];
    layer.backgroundColor = RGBA(255, 255, 255, 1).CGColor;
    layer.shadowColor = RGBA(0, 0, 0, 1.0).CGColor;
    layer.shadowOffset = CGSizeMake(2, 0);
    layer.shadowOpacity = 0.07;
    layer.cornerRadius = 105/2.00;
    
    [layer setFrame:CGRectMake(0, 0, SDMainScreenWidth - 30, 105)];
    [self.bottomView.layer addSublayer:layer];
    
//    [self.sorceView.layer addSublayer:[self getCirclelayer]];

    
}
- (void)setData:(SDDetectionReportData *)data
{
    _data = data;
    
    NSString *sex = data.sex == 0? @"男":@"女";
    [self.sexImage setImage:[UIImage imageNamed:sex]];
    
    NSString *nickTitle = @"昵称:";
    NSString *nickName = data.nickName;
    
    NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",nickTitle,nickName]];
    [att addAttribute:NSForegroundColorAttributeName value:RGBA(163, 161, 162, 1) range:NSMakeRange(0, nickTitle.length)];
    [self.nickName setAttributedText:att];
    self.skinTypeLab.text = NSSTRINGAPPEND(self.data.skinType, @"性肤质");
    
}
- (CALayer *)getCirclelayer
{
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(0, 0, 77, 77);
    //创建圆环
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(77/2.0, 77/2.0) radius:77/2.0 - 5 startAngle:-M_PI_2 - M_PI_4*3/2  endAngle:M_PI - M_PI_4/2 clockwise:YES];
    //圆环遮罩
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.fillColor = [UIColor clearColor].CGColor;
    shapeLayer.strokeColor = [UIColor whiteColor].CGColor;
    shapeLayer.lineWidth = 5;
    shapeLayer.strokeStart = 0;
    shapeLayer.strokeEnd = 1;
    shapeLayer.lineCap = kCALineCapRound;
    shapeLayer.lineDashPhase = 0.8;
    shapeLayer.path = bezierPath.CGPath;
    [layer setMask:shapeLayer];
    
    //颜色渐变
    NSMutableArray *colors = [NSMutableArray arrayWithObjects:(id)RGBA(207, 104, 255, 1).CGColor,(id)[RGBA(255, 120, 155, 1) CGColor], nil];
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.shadowPath = bezierPath.CGPath;
    gradientLayer.frame = CGRectMake(0, 0, 77, 77/2.0);
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1, 0);
    gradientLayer.locations = @[@0.8,@0.9];
    [gradientLayer setColors:[NSArray arrayWithArray:colors]];
    
    NSMutableArray *colors1 = [NSMutableArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor],(id)[RGBA(255, 120, 155, 1) CGColor], nil];
    CAGradientLayer *gradientLayer1 = [CAGradientLayer layer];
    gradientLayer1.shadowPath = bezierPath.CGPath;
    gradientLayer1.frame = CGRectMake(0, 77/2.0, 77, 77/2.0);
    gradientLayer1.startPoint = CGPointMake(0, 0);
    gradientLayer1.endPoint = CGPointMake(1, 0);
    gradientLayer1.locations = @[@0.2,@0.9];
    [gradientLayer1 setColors:[NSArray arrayWithArray:colors1]];
    [layer addSublayer:gradientLayer];
    //设置颜色渐变
    [layer addSublayer:gradientLayer1];
    
    return layer;
}
@end
